home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome_100_percent.pak / Unnamed File 000013.txt < prev    next >
Text File  |  2013-04-03  |  885b  |  28 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Expose a function to watch the HTML tag creation via Mutation Observers.
  6. function watchForTag(tagName, cb) {
  7.   // Query tags already in the document.
  8.   var nodes = document.body.querySelectorAll(tagName);
  9.   for (var i = 0, node; node = nodes[i]; i++) {
  10.     cb(node);
  11.   }
  12.  
  13.   // Observe the tags added later.
  14.   var documentObserver = new WebKitMutationObserver(function(mutations) {
  15.     mutations.forEach(function(mutation) {
  16.       for (var i = 0, addedNode; addedNode = mutation.addedNodes[i]; i++) {
  17.         if (addedNode.tagName == tagName) {
  18.           cb(addedNode);
  19.         }
  20.       }
  21.     });
  22.   });
  23.   documentObserver.observe(document, {subtree: true, childList: true});
  24. }
  25.  
  26. exports.watchForTag = watchForTag;
  27.  
  28.